package ai.people.netmon.facebook.probe.controller;


import ai.people.netmon.facebook.probe.service.FacebookAccountService;
import ai.people.netmon.framework.domain.facebook.probe.entity.FacebookAccount;
import ai.people.netmon.framework.domain.facebook.probe.request.QueryRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
    探测-facebook-用户接口
 *
 * @author zhenglin
 * @since 2022-03-11
 */
@RestController
@RequestMapping("/probe/user")
public class FacebookAccountController {

    @Autowired
    private FacebookAccountService service;

    /**
     * 分页查询页面
     *
     * @param request 请求vo
     * @return {@link Result}<{@link PageResponse}<{@link FacebookAccount}>>
     */
    @PostMapping("/list")
    Result<PageResponse<FacebookAccount>> queryPage(@RequestBody QueryRequest request) {
        PageResponse<FacebookAccount> list = service.queryPage(request);
        return ResultUtil.success(list);
    }

    /**
     * 添加facebook账号
     *
     * @param account facebook账号
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/")
    Result<Boolean> add(@Valid @RequestBody FacebookAccount account){
        service.saveAccount(account);
        return ResultUtil.success();
    }

    /**
     * 更新facebook账号信息
     *
     * @param account facebook账号
     * @return {@link Result}<{@link Boolean}>
     */
    @PutMapping
    Result<Boolean> update(@RequestBody FacebookAccount account){
        service.updateAccount(account);
        return ResultUtil.success();
    }

    /**
     * 通过用户id获取facebook用户信息
     *
     * @param id 用户ID
     * @return {@link Result}<{@link FacebookAccount}>
     */
    @GetMapping("/{uid}")
    Result<FacebookAccount> getUserById(@PathVariable("uid") @NotBlank Long id){
        FacebookAccount account = service.getUserById(id);
        return ResultUtil.success(account);
    }

    /**
     * 批量保存facebook账号信息
     *
     * @param list facebook账号信息集合
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/batchSave")
    Result<Boolean> saveBatch(@RequestBody List<FacebookAccount> list){
        service.saveBatchData(list);
        return ResultUtil.success();
    }

}
